//
//  BannerViewController.m
//  UILbrary
//
//  Created by 斌 on 2017/8/8.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "BannerViewController.h"
#import "UILbrary-Swift.h"
#import "SnapKit-Swift.h"
//#import ""
@interface BannerViewController ()<BannerViewDelegate>

/// 网络图片地址数组
@property (nonatomic, strong) NSArray *imageUrlArr;
/// 标题数组
@property (nonatomic, strong) NSArray *titleArr;
@end

@implementation BannerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    // 记得把这句代码封装到 模块里面
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"轮播图";
    
    //CGRect frame = CGRectMake(0, 64, self.view.bounds.size.width, 200);
    
    UIImage *placeImage = [UIImage imageNamed:@"1"];
    
    //BannerView *banner = [[BannerView alloc] initWithFrame:frame viewController:self  imageArr:self.imageUrlArr placeHoldImage:placeImage titleArr:self.titleArr];
    BannerView *banner = [UIView new];
//    [[BannerView alloc] initWithViewController:self imageArr:self.imageUrlArr placeHoldImage:placeImage titleArr:self.titleArr];

    [self.view addSubview:banner];
    // 这里用 layout 布局
    
    banner.translatesAutoresizingMaskIntoConstraints = NO;

    NSLayoutConstraint * constraint1 = [banner.topAnchor constraintEqualToAnchor:self.view.topAnchor];
    NSLayoutConstraint * constraint2 = [banner.leftAnchor constraintEqualToAnchor:self.view.leftAnchor];
    NSLayoutConstraint * constraint3 = [banner.rightAnchor constraintEqualToAnchor:self.view.rightAnchor];
    NSLayoutConstraint *heightConstraint = [banner.heightAnchor constraintEqualToConstant:200];
    // 约束添加在父视图上
    [self.view addConstraints:@[constraint1,constraint2,constraint3,heightConstraint]];
}

//MARK: - 轮播图点击事件

- (void)didSelectItemAtNumeber:(NSInteger)atNumeber bannerView:(BannerView *)bannerView{
    NSLog(@"点击了第 %ld '个图片 OC",(long)atNumeber);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//MARK: - lazy 方法
- (NSArray *)imageUrlArr{
    if (!_imageUrlArr) {
        _imageUrlArr =  @[@"http://61.144.248.2:8085/carManager/html/ueditor/jsp/upload/info/2017/08/11/pic_1502416479862.jpg",
                          
                          @"http://61.144.248.2:8085/carManager/html/ueditor/jsp/upload/info/2017/08/10/pic_1502331229612.jpg",
                          
                          @"http://61.144.248.2:8085/carManager/html/ueditor/jsp/upload/info/2017/08/07/pic_1502085582890.jpg",
                          
                          @"http://61.144.248.2:8085/carManager/html/ueditor/jsp/upload/info/2017/08/07/pic_1502085108072.jpg",
                          
                          @"http://61.144.248.2:8085/carManager/html/ueditor/jsp/upload/info/2017/08/04/pic_1501819284994.jpg",
                          @"http://61.144.248.2:8085/carManager/html/ueditor/jsp/upload/info/2017/07/31/pic_1501466845618.jpg"];
    }
    return _imageUrlArr;
}

- (NSArray *)titleArr{
    if (!_titleArr) {
        _titleArr = @[@"标题1",
                      @"标题2",
                      @"标题3",
                      @"标题4",
                      @"标题5",
                      @"标题6"];
        
    }
    return _titleArr;
}
@end
